#include <bits/stdc++.h>
// 2025/05/07
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, k, cnt, p[1000001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) 
        if (__gcd(i, n) == 1) 
            p[++cnt] = i;
    cout << (k - 1) / cnt * n + p[(k - 1) % cnt + 1]<< endl;
    return 0;
}